@using System
@using RazorLight
@inherits TemplatePage<RestApiSpec>
@using System.Collections.Generic
@using System.Linq
@using System.Net.Cache
@using ApiGenerator.Domain
@using ApiGenerator
@using CsQuery.ExtensionMethods.Internal

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Elasticsearch.Net;
using Newtonsoft.Json;

//This file contains all the typed querystring parameters that are generated of the client spec.
//This file is automatically generated from https://github.com/elastic/elasticsearch/tree/master/rest-api-spec

namespace Nest
{
@{
	RestApiSpec m = Model;
	var methods = m.CsharpMethodsWithQueryStringInfo
		.Concat(m
			.CsharpMethodsWithQueryStringInfo
			.Where(s=>s.RequestTypeGeneric == "<T>")
			.Select(s=> { var ss = CsharpMethod.Clone(s); ss.RequestTypeGeneric = ""; ss.SkipInterface = true; return ss; })
		)
		.OrderBy(s=>s.RequestType);
}
	public abstract partial class @Raw("PlainRequestBase<TParameters>")
	{
	@foreach (var common in RestApiSpec.CommonApiQueryParameters.Values)
	{
<text>		@Raw(common.InitializerGenerator(common.TypeHighLevel, common.ClsName, common.QueryStringKey, "value", common.DescriptionHighLevel.ToArray()))
</text>
	}
	}
	@foreach (CsharpMethod method in methods)
	{
	if (!method.SkipInterface)
	{
	<text>
	[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
	public partial interface @(Raw(method.InterfaceType)) : IRequest@(Raw(string.Format("<{0}>", method.QueryStringParamName)))
	{
</text>
	foreach (ApiUrlPart part in method.AllParts.Where(p=>!ApiUrl.BlackListRouteValues.Contains(p.Name)))
	{
<text>		@(Raw(part.ClrTypeName)) @(part.InterfaceName) { get; }
</text>
	}
	//render partial methods as interface properties forcing us to implement them on request and request descriptors
	if (method.HttpMethod != "GET" && method.HttpMethod != "HEAD")
	{
		foreach (var partialParam in method.Url.Params.Values.Where(p=>p.RenderPartial))
		{
		<text>[JsonProperty("@(partialParam.QueryStringKey)")] @(Raw(partialParam.TypeHighLevel)) @(partialParam.ClsName) { get; set; }</text>
		}
	}
<text>	}
</text>
	}
<text>	///<summary>Request parameters for @method.FullName <pre>@method.Documentation</pre></summary>
	public partial class @Raw(method.RequestType + method.RequestTypeGeneric) @Raw(string.Format(": PlainRequestBase<{0}>, {1}", method.QueryStringParamName, method.InterfaceType))
	{
		protected @(Raw(method.InterfaceType)) Self => this;
@foreach (Constructor c in method.RequestConstructors())
{
<text>		@(Raw(CodeGenerator.Constructor(c)))
</text>
}
		// values part of the url path
@foreach (var part in method.AllParts.Where(p=>!ApiUrl.BlackListRouteValues.Contains(p.Name)))
{
<text>		@(Raw(part.ClrTypeName)) @(Raw(method.InterfaceType)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>", part.ClrTypeName)))("@(part.Name)");
</text>
}

		// Request parameters
@foreach (var param in method.Url.Params.Values)
{
	var original = param.QueryStringKey;
	//skip parameters already part of the path portion of the url
	if (method.Url.Parts != null && method.Url.Parts.ContainsKey(original))
	{
		continue;
	}
	//we prefer this parameter to be explictly implemented on the request body
	if (param.RenderPartial && (method.HttpMethod != "GET" && method.HttpMethod != "HEAD"))
	{
		continue;
	}
	var doc = param.DescriptionHighLevel.ToArray();
<text>		@Raw(param.InitializerGenerator(param.TypeHighLevel, param.ClsName, original, param.SetterHighLevel, doc))
</text>
}
@if (method.RequestTypeUnmapped)
{<text>		//TODO THIS METHOD IS UNMAPPED!
</text>
}
	}</text>
}
}
